package net.lzzy.practicesapi1.web.models;

import lombok.Getter;
import lombok.Setter;
import net.lzzy.practicesapi1.entities.User;
import net.lzzy.practicesapi1.utils.JwtUtil;

import java.util.UUID;
/**
 * @author lyz
 */
@Getter
@Setter
public class VmUser {
    private UUID id;
    private String userName;
    private String nickName;
    private String phone;
    private String email;
    private String avatar;
    private String token;
    private int type;
    private VmUser(){}
    private VmUser(User user){
        id=user.getId();
        userName= user.getUserName();
        nickName=user.getNickName();
        phone=user.getPhone();
        email=user.getEmail();
        avatar=user.getAvatar();
        type=user.getType();
    }
    public static VmUser apiLogin(User user){
        VmUser vm=new VmUser(user);
        vm.setToken(JwtUtil.createToken(user.getId()+""));
        return vm;
    }
    public static VmUser create(User user,boolean admin){
        VmUser vm=new VmUser(user);
        if (!admin){
            user.setUserName("");
            user.setType(User.TYPE_STUDENT);
        }
        return vm;
    }
}
